﻿/******************************/
$(document).ready(function () {
    doSetMenuItemEnable(false); //默认无选中状态，相关按钮禁用
    doSetLiWidth('100', '120');
});
//设置LI的宽度
var doSetLiWidth = function (evenWidth, oddWidth) {
    $('.ui-list li:even').width(evenWidth).css('text-align', 'right').css('line-height', '21px').css('padding-right', '0px');
    $('.ui-list li:odd').width(oddWidth);
}

//启用否禁用指定按钮
function doSetMenuItemEnable(val) {
    var menuNameCollection = ['btnView','btnEdit', 'btnDelete'];
    for (var item in menuNameCollection) {
        var menuItem = menuHeader.GetItemByName(menuNameCollection[item]);
        if (menuItem) {
            menuItem.SetEnabled(val);
        }
    }
}

function doSetMenuItemEnable2(val) {
    var menuNameCollection = ['btnEdit', 'btnDelete', 'btnBulkEdit', 'btnRefresh'];
    for (var item in menuNameCollection) {
        var menuItem = menuHeader.GetItemByName(menuNameCollection[item]);
        if (menuItem) {
            menuItem.SetEnabled(val);
        }
    }
}


//控件集合实例
var collCell;
var AutoGennoList;
//页面加载完成
$(document).ready(function () {
    var collection = [
      New(ASPxRFTextBox, ['txtNoclass', ['GroupA'], 'Noclass']),
      New(ASPxRFTextBox, ['txtCreatename', ['GroupA'], 'Createname']),
      New(ASPxRFRadioButtonList, ['rblAutogenid', ['GroupA'], { valueField: 'Autogenid'}]),
      New(ASPxRFTextBox, ['txtModifyname', ['GroupA'], 'Modifyname']),
      New(ASPxRFDateEdit, ['deCreatedate', ['GroupA'], 'Createdate', 'yyyy-MM-dd HH:mm:ss'])
    ];

    collCell = New(RapidForm, [collection]);
    //页面简写
    AutoGennoList = SGRapidForm.Foundation.AutoGenno;

});
//gvwList 选择事件
function doSelect() {
    //获得gvwList选中的行数
    var selectedCount = gvwList.GetSelectedRowCount();
    //只有新增可用，其他不可用
    if (selectedCount == 0) {
        doSetMenuItemEnable(false);
    } else if (selectedCount == 1) {//全部可用
        doSetMenuItemEnable(true);
    } else if (selectedCount > 1) {//编辑不可用，其他可用
        doSetMenuItemEnable(true);
        var menuItem = menuHeader.GetItemByName('btnEdit');
        menuItem.SetEnabled(false);
        var menuItem = menuHeader.GetItemByName('btnView');
        menuItem.SetEnabled(false);
    }
}
//双击打开明细 closeCurrentTab
function doSelectedItem(s, e) {
    var keyid = gvwList.GetRowKey(e.visibleIndex);
    top.navTab.openTab('Views/Foundation/Common/AutoGennoDetail.aspx?State=LOAD&Keyid=' + keyid, 'Views/Foundation/Common/AutoGennoDetail.aspx?State=LOAD&Keyid=' + keyid, { title: '自动编码明细', fresh: true, external: true, data: {} });
}
//刷新
var doRefresh = function () {
    $('#hfFilterCondition').val(' ')
    gvwList.PerformCallback();
}
//查找
var doSearch = function () {
    doDisplay('search');
    doSetMenuItemEnable2(false);
}
//显示指定DIV
var doDisplay = function (id) {
    if ($('#' + id).hasClass('ui-content-item-selected')) {
        return;
    } else {
        $('.ui-content-item-selected').removeClass('ui-content-item-selected');
        $('#' + id).addClass('ui-content-item-selected');
    }
}

//点击查询按钮
function doSubmittedToSearch(s, e) {
    doListAll();
    $('#hfFilterCondition').val(collCell.getQueryString('GroupA'));
    gvwList.PerformCallback();
    menuHeader.SetSelectedItem(menuHeader.GetItemByName('btnListAll'));
}
//显示所有
var doListAll = function () {
    doDisplay('listall');
    doSelect();
    doSetMenuItemRefreshEnable(true);
}
//让刷新按钮启用
function doSetMenuItemRefreshEnable(val) {
    var menuItem = menuHeader.GetItemByName('btnRefresh');
    menuItem.SetEnabled(val);
}
//查找重置
var doResetToSearch = function (s, e) {
    collCell.reset('GroupA');
}
//删除
var doBulkDelete = function () {
    $.messager.confirm('确认提示', '确认删除吗?', function (result) {
        if (result) {
            //获取选择记录Keyids
            var keyids = gvwList.GetSelectedKeysOnPage().join('_');
            //调用删除方法
            AutoGennoList.BulkDelete(keyids, function (result) {
                if (result.value) {
                    gvwList.PerformCallback();
                    $.messager.show({
                        title: '信息提示',
                        msg: '删除成功！',
                        showType: 'slide'
                    });

                } else {
                    $.messager.show({
                        title: '信息提示',
                        msg: '删除失败！',
                        showType: 'slide'
                    });
                }
            });
        }
    });
}
//查看
var doView = function () {

    var keyid = gvwList.GetSelectedKeysOnPage()
    top.navTab.openTab('Views/Foundation/Common/AutoGennoDetail.aspx?State=LOAD&Keyid=' + keyid, 'Views/Foundation/Common/AutoGennoDetail.aspx?State=LOAD&Keyid=' + keyid, { title: '自动编码明细', fresh: true, external: true, data: {} });
}
//编辑
var doEdit = function () {
    var keyid = gvwList.GetSelectedKeysOnPage()[0];
    top.navTab.openTab('Views/Foundation/Common/AutoGennoDetail.aspx?State=EDIT&Keyid=' + keyid, 'Views/Foundation/Common/AutoGennoDetail.aspx?State=EDIT&Keyid=' + keyid, { title: '自动编码明细', fresh: true, external: true, data: {} });
}

//新增
var doAdd = function () {
    //根据当前时间生成无重复ID
    var autoId = new Date().getTime().toString();
    top.navTab.openTab('Views/Foundation/Common/AutoGennoDetail.aspx?State=ADD&AutoId=' + autoId, 'Views/Foundation/Common/AutoGennoDetail.aspx?State=ADD', { title: '自动编码明细', fresh: true, external: true, data: {} });
}
//添加快捷方式
var doSetShortcut = function () {
    SGRapidForm.Foundation.AutoGenno.SaveFastAdd(function (result) {
        if (result.value) {
            $.messager.show({
                title: '信息提示',
                msg: '添加快捷方式成功！',
                showType: 'slide'
            });

        } else {
            $.messager.show({
                title: '信息提示',
                msg: '添加快捷方式失败！',
                showType: 'slide'
            });
        }

    });
}